#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import Exec

def getHostname(host = "localhost"):
    '''
    Return Fully Qualified Domain Name of the server
    '''
    return(Exec.runCmd('hostname --fqdn')[1][0][:-1])

def getServices():
    '''
    Return a list of services launched at startup (archlinux only)
    '''
    rawservices = Exec.runCmd('grep DAEMONS= /etc/rc.conf')[1][0][9:-2]
    services = []
    for i in rawservices.split():
        if i[0] != '!':
            if i[0] == '@':
                services.append(i[1:])
            else:
                services.append(i)
    return(services)

def getDisks():
    '''
    Return the list of all ATA disks in the server
    '''
    disks = []
    for i in Exec.runCmd('ls /dev | grep sd.$')[1][0].split('\n')[:-1]:
        disks.append(i)
    if len(disks) == 0:
        for i in Exec.runCmd('ls /dev | grep hd.$')[1][0].split('\n')[:-1]:
            disks.append(i)
    return(disks)

def getParts():
    '''
    Return the list of partitions in the server
    '''
    parts = []
    for i in getDisks():
        for j in Exec.runCmd('ls /dev | grep ' + i + '.$')[1][0].split('\n')[:-1]:
            parts.append(j)
    return(parts)
